﻿using System;
using System.Text;

namespace MeTool.BarCode
{
    /// <summary>二维码生成</summary>
    public class QRCode
    {
        /// <summary>二维码生成</summary>
        public QRCode()
        {
            lFormatFirstX = new byte[] { 0, 1, 2, 3, 4, 5, 7, 8, 8, 8, 8, 8, 8, 8, 8 };
            lFormatFirstY = new byte[] { 8, 8, 8, 8, 8, 8, 8, 8, 7, 5, 4, 3, 2, 1, 0 };
            lFormatSecondX = new byte[15];
            lFormatSecondY = new byte[15];
            Constract();
        }

        /// <summary>
        /// 当指定字符属于字母模式字符时返回True
        /// </summary>
        /// <param name="QRTextChar"></param>
        /// <returns></returns>
        /// <remarks></remarks>
        private static bool CheckTextCharAlphaNumeric(char QRTextChar)
        {
            return QRTextChar >= '0' && QRTextChar <= '9' || QRTextChar >= 'A' && QRTextChar <= 'Z' || " $%*+-./:".Contains(QRTextChar.ToString());
        }

        /// <summary>
        /// 当指定字符属于数字模式字符时返回True
        /// </summary>
        /// <param name="QRTextChar"></param>
        /// <returns></returns>
        /// <remarks></remarks>
        private static bool CheckTextCharNumeric(char QRTextChar)
        {
            return QRTextChar >= '0' && QRTextChar <= '9';
        }

        private void Constract()
        {
            AddChechDigit = false;
            WriteDebugInfo = false;
            QRCodeConstract();
        }

        private static byte QRCodeChooseMaskNumber(byte[,] pModuleData, int pExtraBits)
        {
            int length = pModuleData.GetLength(0);
            int[] numArray2 = new int[8];
            int[] numArray3 = new int[8];
            int[] numArray4 = new int[8];
            int[] numArray5 = new int[8];
            int[] numArray6 = new int[8];
            int[] numArray7 = new int[8];
            int num = 0;
            int num2 = 0;
            int[] numArray8 = new int[9];
            int[] numArray9 = new int[9];
            bool[] flagArray = new bool[9];
            bool[] flagArray2 = new bool[9];

            int num3 = length - 1;
            for (int i = 0; i <= num3; i++)
            {
                int num4 = 0;
                do
                {
                    numArray8[num4] = 0;
                    numArray9[num4] = 0;
                    flagArray[num4] = false;
                    flagArray2[num4] = false;
                    num4++;
                }
                while (num4 <= 7);
                for (int j = 0; j < length; j++)
                {
                    if (j > 0 & i > 0)
                    {
                        num = pModuleData[j, i] & pModuleData[j - 1, i] & pModuleData[j, i - 1] & pModuleData[j - 1, i - 1];
                        num2 = pModuleData[j, i] | pModuleData[j - 1, i] | pModuleData[j, i - 1] | pModuleData[j - 1, i - 1];
                    }
                    int num6 = 0;
                    do
                    {
                        numArray8[num6] = (numArray8[num6] & 63) << 1 | (byte)((uint)pModuleData[j, i] >> (num6 & 7 & 7)) & 1;
                        numArray9[num6] = (numArray9[num6] & 63) << 1 | (byte)((uint)pModuleData[i, j] >> (num6 & 7 & 7)) & 1;
                        if ((pModuleData[j, i] & 1 << num6) != 0)
                        {
                            int num7 = num6;
                            int[] array = numArray5;
                            int num11 = num7;
                            array[num11] += 1;
                        }
                        if (numArray8[num6] == Convert.ToInt32("1011101", 2))
                        {
                            int num7 = num6;
                            numArray4[num7] += 40;
                        }
                        if (numArray9[num6] == Convert.ToInt32("1011101", 2))
                        {
                            int num7 = num6;
                            numArray4[num7] += 40;
                        }
                        if (j > 0 & i > 0)
                        {
                            if ((num & 1) != 0 | (num2 & 1) == 0)
                            {
                                int num7 = num6;
                                numArray3[num7] += 3;
                            }
                            num >>= 1;
                            num2 >>= 1;
                        }
                        if ((numArray8[num6] & 31) == 0 | (numArray8[num6] & 31) == 31)
                        {
                            if (j > 3)
                            {
                                if (flagArray[num6])
                                {
                                    int num7 = num6;
                                    int[] array2 = numArray2;
                                    int num12 = num7;
                                    ref int ptr = ref array2[num12];
                                    array2[num12] = ptr + 1;
                                }
                                else
                                {
                                    int num7 = num6;
                                    numArray2[num7] += 3;
                                    flagArray[num6] = true;
                                }
                            }
                        }
                        else
                        {
                            flagArray[num6] = false;
                        }
                        if ((numArray9[num6] & 31) == 0 | (numArray9[num6] & 31) == 31)
                        {
                            if (j > 3)
                            {
                                if (flagArray2[num6])
                                {
                                    int num7 = num6;
                                    int[] array3 = numArray2;
                                    int num13 = num7;
                                    array3[num13] += 1;
                                }
                                else
                                {
                                    int num7 = num6;
                                    numArray2[num7] += 3;
                                    flagArray2[num6] = true;
                                }
                            }
                        }
                        else
                        {
                            flagArray2[num6] = false;
                        }
                        num6++;
                    }
                    while (num6 <= 7);
                }
            }
            int[] numArray10 = new int[] { 90, 80, 70, 60, 50, 40, 30, 20, 10, 0, 0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 90 };
            int index = 0;
            do
            {
                numArray6[index] = numArray10[20 * numArray5[index] / pExtraBits];
                numArray7[index] = numArray2[index] + numArray3[index] + numArray4[index] + numArray6[index];
                index++;
            }
            while (index <= 7);
            int num8 = 0;
            byte num9 = 0;
            int num10 = 0;
            do
            {
                if (numArray7[num10] < num8 | num10 == 0)
                {
                    num9 = (byte)num10;
                    num8 = numArray7[num10];
                }
                num10++;
            }
            while (num10 <= 7);
            return num9;
        }

        private void QRCodeConstract()
        {
            QRSetECCRate = QRECCRates.Medium15Percent;
            QRSetTextType = QRTextTypes.Automatic;
            lQRSetVersion = QRVersions.Automatic;
            gDataWords = new int[,]
            {
                { 19, 34, 55, 80, 108, 68,78, 97, 116, 68, 81, 92, 107, 115, 87, 98, 107, 120, 113, 107, 116, 111, 121, 117, 106, 114, 122, 117, 116, 115, 115, 115, 115, 115, 121, 121, 122, 122, 117, 118 },
                { 16, 28, 44, 32, 43, 27, 31, 38, 36, 43, 50, 36, 37, 40, 41, 45, 46, 43, 44, 41, 42, 46, 47, 45, 47, 46, 45, 45, 45, 47, 46, 46, 46, 46, 47, 47, 46, 46,  47, 47  },
                { 13, 22, 17, 24, 15, 19, 14, 18, 16, 19, 22, 20, 20, 16, 24, 19, 22, 22, 21, 24, 22, 24, 24, 24, 24, 22, 23, 24, 23, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24 },
                { 9, 16, 13, 9, 11, 15, 13, 14, 12, 15, 12, 14, 11, 12, 12, 15, 14, 14, 13, 15, 16, 13, 15, 16, 15, 16, 15, 15, 15, 15, 15, 15, 15, 16, 15, 15, 15, 15, 15, 15 }
            };
            gExtraDataWords = new int[,]
            {
                { 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, 1, 1, 1, 5, 1, 4, 5, 4, 7, 5, 4, 4, 2, 4, 10, 7, 10, 3, 0, 1, 6, 7, 14, 4, 18, 4, 6 },
                { 0, 0, 0, 0, 0, 0, 0, 2, 2, 1, 4, 2, 1, 5, 5, 3, 1, 4, 11, 13, 0, 0, 14, 14, 13, 4, 3, 23, 7, 10, 29, 23, 21, 23, 26, 34, 14, 32, 7, 31 },
                { 0, 0, 0, 0, 2, 0, 4, 2, 4, 2, 4, 6, 4, 5, 7, 2, 15, 1, 4, 5, 6, 16, 14, 16, 22, 6, 26, 31, 37, 25, 1, 35, 19, 7, 14, 10, 10, 14, 22, 34 },
                { 0, 0, 0, 0, 2, 0, 1, 2, 4, 2, 8, 4, 4, 5, 7, 13, 17, 19, 16, 10, 6, 0, 14, 2, 13, 4, 28, 31, 26, 25, 28, 35, 46, 1, 41, 64, 46, 32, 67, 61 }
            };
            gECCWords = new int[,]
            {
                { 7, 10, 15, 20, 26, 18, 20, 24, 30, 18, 20, 24, 26, 30, 22, 24, 28, 30, 28, 28, 28, 28, 30, 30, 26, 28, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30 },
                { 10, 16, 26, 18, 24, 16, 18, 22, 22, 26, 30, 22, 22, 24, 24, 28, 28, 26, 26, 26, 26, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28 },
                { 13, 22, 18, 26, 18, 24, 18, 22, 20, 24, 28, 26, 24, 20, 30, 24, 28, 28, 26, 30, 28, 30, 30, 30, 30, 28, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30 },
                { 17, 28, 22, 16, 22, 28, 26, 26, 24, 28, 24, 28, 22, 24, 24, 30, 28, 28, 26, 28, 30, 24, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30 }
            };
            gRSBlockCount = new int[,]
            {
                { 1, 1, 1, 1, 1, 2, 2, 2, 2, 4, 4, 4, 4, 4, 6, 6, 6, 6, 7, 8, 8, 9, 9, 10, 12, 12, 12, 13, 14, 15, 16, 17, 18, 19, 19, 20, 21, 22, 24, 25 },
                { 1, 1, 1, 2, 2, 4, 4, 4, 5, 5, 5, 8, 9, 9, 10, 10, 11, 13, 14, 16, 17, 17, 18, 20, 21, 23, 25, 26, 28, 29, 31, 33, 35, 37, 38, 40, 43, 45, 47, 49 },
                { 1, 1, 2, 2, 4, 4, 6, 6, 8, 8, 8, 10, 12, 16, 12, 17, 16, 18, 21, 20, 23, 23, 25, 27, 29, 34, 34, 35, 38, 40, 43, 45, 48, 51, 53, 56, 59, 62, 65, 68 },
                { 1, 1, 2, 4, 4, 4, 5, 6, 8, 8, 11, 11, 16, 16, 18, 16, 19, 21, 25, 25, 25, 34, 30, 32, 35, 37, 40, 42, 45, 48, 51, 54, 57, 60, 63, 66, 70, 74, 77, 81 }
            };
        }

        private static int QRCodeGet1DimensionAddress(int pX, int pY, int pSymbolSize)
        {
            return checked(pX + pY * (pSymbolSize + 1));
        }

        private static byte[] QRCodeGet8BitData(int[] pInputData, byte[] pInputDataBits, int pMaxBytes)
        {
            byte[] buffer = new byte[pMaxBytes - 1 + 1 - 1 + 1];
            int length = pInputDataBits.Length;
            int index = 0;
            int num3 = 8;
            int num4 = 0;
            for (int i = 0; i < length; i++)
            {
                num4 += pInputDataBits[i];
            }
            for (int j = 0; j <= (num4 - 1) / 8; j++)
            {
                buffer[j] = 0;
            }
            for (int k = 0; k < length; k++)
            {
                int num8 = pInputData[k];
                int num9 = pInputDataBits[k];
                bool flag = true;
                bool flag2 = num9 != 0;
                if (!flag2)
                {
                    break;
                }
                for (; ; )
                {
                    bool flag3 = flag;
                    if (!flag3)
                    {
                        break;
                    }
                    if (num3 > num9)
                    {
                        buffer[index] = (byte)(unchecked((byte)(buffer[index] << (num9 & 7 & 7))) | num8);
                        num3 -= num9;
                        flag = false;
                    }
                    else
                    {
                        num9 -= num3;
                        buffer[index] = (byte)(unchecked((byte)(buffer[index] << (num3 & 7 & 7))) | num8 >> num9);
                        if (num9 == 0)
                        {
                            flag = false;
                        }
                        else
                        {
                            num8 &= (1 << num9) - 1;
                            flag = true;
                        }
                        index++;
                        num3 = 8;
                    }
                }
            }
            if (num3 != 8)
            {
                buffer[index] = unchecked((byte)(buffer[index] << (num3 & 7 & 7)));
            }
            else
            {
                index--;
            }
            if (index < pMaxBytes - 1)
            {
                bool flag = true;
                while (index < pMaxBytes - 1)
                {
                    index++;
                    if (flag)
                    {
                        buffer[index] = 236;
                    }
                    else
                    {
                        buffer[index] = 17;
                    }
                    flag = !flag;
                }
            }
            return buffer;
        }

        private static byte[] QRCodeGetByteData(byte[] pInput1, byte[] pInput2)
        {
            bool flag = pInput1.Length > pInput2.Length;
            byte[] buffer2;
            byte[] buffer3;
            if (flag)
            {
                buffer2 = (byte[])pInput1.Clone();
                buffer3 = (byte[])pInput2.Clone();
            }
            else
            {
                buffer2 = (byte[])pInput2.Clone();
                buffer3 = (byte[])pInput1.Clone();
            }
            int length = buffer2.Length;
            int num2 = buffer3.Length;
            checked
            {
                byte[] buffer4 = new byte[length + 1 - 1 + 1];
                int num3 = length - 1;
                for (int i = 0; i <= num3; i++)
                {
                    bool flag2 = i < num2;
                    if (flag2)
                    {
                        buffer4[i] = (byte)(buffer2[i] ^ buffer3[i]);
                    }
                    else
                    {
                        buffer4[i] = buffer2[i];
                    }
                }
                return buffer4;
            }
        }

        private static byte[] QRCodeGetFormatX(int pVersion)
        {
            byte[] buffer = new byte[16];
            int index = 0;
            checked
            {
                do
                {
                    buffer[index] = 8;
                    index++;
                }
                while (index <= 6);
                int num2 = 0;
                do
                {
                    buffer[num2 + 7] = (byte)(4 * pVersion + 9 + num2);
                    num2++;
                }
                while (num2 <= 7);
                return buffer;
            }
        }

        private static byte[] QRCodeGetFormatY(int pVersion)
        {
            byte[] buffer = new byte[16];
            int num = 0;
            checked
            {
                do
                {
                    buffer[num + 7] = 8;
                    num++;
                }
                while (num <= 7);
                int index = 0;
                do
                {
                    buffer[index] = (byte)(4 * pVersion + 16 - index);
                    index++;
                }
                while (index <= 6);
                return buffer;
            }
        }

        private static bool QRCodeGetMaskBit(int pMaskPatternNo, int pY, int pX)
        {
            checked
            {
                bool QRCodeGetMaskBit;
                switch (pMaskPatternNo)
                {
                    case 0:
                        {
                            bool flag2 = (pX + pY) % 2 != 0;
                            QRCodeGetMaskBit = !flag2;
                            break;
                        }
                    case 1:
                        {
                            bool flag3 = pX % 2 != 0;
                            QRCodeGetMaskBit = !flag3;
                            break;
                        }
                    case 2:
                        {
                            bool flag4 = pY % 3 != 0;
                            QRCodeGetMaskBit = !flag4;
                            break;
                        }
                    case 3:
                        {
                            bool flag5 = (pX + pY) % 3 != 0;
                            QRCodeGetMaskBit = !flag5;
                            break;
                        }
                    case 4:
                        {
                            bool flag6 = ((double)pX / 2 + (double)pY / 3) % 2 != 0;
                            QRCodeGetMaskBit = !flag6;
                            break;
                        }
                    case 5:
                        {
                            bool flag7 = pX * pY % 2 + pX * pY % 3 != 0;
                            QRCodeGetMaskBit = !flag7;
                            break;
                        }
                    case 6:
                        {
                            bool flag8 = (pX * pY % 2 + pX * pY % 3) % 2 != 0;
                            QRCodeGetMaskBit = !flag8;
                            break;
                        }
                    case 7:
                        {
                            bool flag9 = (pX * pY % 3 + (pX + pY) % 2) % 2 != 0;
                            QRCodeGetMaskBit = !flag9;
                            break;
                        }
                    default:
                        {
                            QRCodeGetMaskBit = false;
                            break;
                        }
                }
                return QRCodeGetMaskBit;
            }
        }

        private static int QRCodeGetMaskBitGroup(int pY, int pX)
        {
            int num = 0;
            bool flag = QRCodeGetMaskBit(0, pY, pX);
            checked
            {
                if (flag)
                {
                    num = (int)Math.Round((double)(num + 1));
                }
                bool flag2 = QRCodeGetMaskBit(1, pY, pX);
                if (flag2)
                {
                    num = (int)Math.Round((double)(num + 2));
                }
                bool flag3 = QRCodeGetMaskBit(2, pY, pX);
                if (flag3)
                {
                    num = (int)Math.Round((double)(num + 4));
                }
                bool flag4 = QRCodeGetMaskBit(3, pY, pX);
                if (flag4)
                {
                    num = (int)Math.Round((double)(num + 8));
                }
                bool flag5 = QRCodeGetMaskBit(4, pY, pX);
                if (flag5)
                {
                    num = (int)Math.Round((double)(num + 16));
                }
                bool flag6 = QRCodeGetMaskBit(5, pY, pX);
                if (flag6)
                {
                    num = (int)Math.Round((double)(num + 32));
                }
                bool flag7 = QRCodeGetMaskBit(6, pY, pX);
                if (flag7)
                {
                    num = (int)Math.Round((double)(num + 64));
                }
                bool flag8 = QRCodeGetMaskBit(7, pY, pX);
                if (flag8)
                {
                    num = (int)Math.Round((double)(num + 128));
                }
                return num;
            }
        }

        private byte[] QRCodeGetSymbolData(int pVersion)
        {
            checked
            {
                int pSymbolSize = pVersion * 4 + 17;
                //int num4 = pSymbolSize * pSymbolSize;
                byte[] buffer2 = new byte[]
                {
                    3,
                    (byte)(pSymbolSize - 1 - 3)
                };
                byte[] buffer3;
                switch (pVersion)
                {
                    case 1:
                        buffer3 = new byte[] { 6 };
                        break;
                    case 2:
                        buffer3 = new byte[] { 6, 18 };
                        break;
                    case 3:
                        buffer3 = new byte[] { 6, 22 };
                        break;
                    case 4:
                        buffer3 = new byte[] { 6, 26 };
                        break;
                    case 5:
                        buffer3 = new byte[] { 6, 30 };
                        break;
                    case 6:
                        buffer3 = new byte[] { 6, 34 };
                        break;
                    case 7:
                        buffer3 = new byte[] { 6, 22, 38 };
                        break;
                    case 8:
                        buffer3 = new byte[] { 6, 24, 42 };
                        break;
                    case 9:
                        buffer3 = new byte[] { 6, 26, 46 };
                        break;
                    case 10:
                        buffer3 = new byte[] { 6, 28, 50 };
                        break;
                    case 11:
                        buffer3 = new byte[] { 6, 30, 54 };
                        break;
                    case 12:
                        buffer3 = new byte[] { 6, 32, 58 };
                        break;
                    case 13:
                        buffer3 = new byte[] { 6, 34, 62 };
                        break;
                    case 14:
                        buffer3 = new byte[] { 6, 26, 46, 66 };
                        break;
                    case 15:
                        buffer3 = new byte[] { 6, 26, 48, 70 };
                        break;
                    case 16:
                        buffer3 = new byte[] { 6, 26, 50, 74 };
                        break;
                    case 17:
                        buffer3 = new byte[] { 6, 30, 54, 78 };
                        break;
                    case 18:
                        buffer3 = new byte[] { 6, 30, 56, 82 };
                        break;
                    case 19:
                        buffer3 = new byte[] { 6, 30, 58, 86 };
                        break;
                    case 20:
                        buffer3 = new byte[] { 6, 34, 62, 90 };
                        break;
                    case 21:
                        buffer3 = new byte[] { 6, 28, 50, 72, 94 };
                        break;
                    case 22:
                        buffer3 = new byte[] { 6, 26, 50, 74, 98 };
                        break;
                    case 23:
                        buffer3 = new byte[] { 6, 30, 54, 78, 102 };
                        break;
                    case 24:
                        buffer3 = new byte[] { 6, 28, 54, 80, 106 };
                        break;
                    case 25:
                        buffer3 = new byte[] { 6, 32, 58, 84, 110 };
                        break;
                    case 26:
                        buffer3 = new byte[] { 6, 30, 58, 86, 114 };
                        break;
                    case 27:
                        buffer3 = new byte[] { 6, 34, 62, 90, 118 };
                        break;
                    case 28:
                        buffer3 = new byte[] { 6, 26, 50, 74, 98, 122 };
                        break;
                    case 29:
                        buffer3 = new byte[] { 6, 30, 54, 78, 102, 126 };
                        break;
                    case 30:
                        buffer3 = new byte[] { 6, 26, 52, 78, 104, 130 };
                        break;
                    case 31:
                        buffer3 = new byte[] { 6, 30, 56, 82, 108, 134 };
                        break;
                    case 32:
                        buffer3 = new byte[] { 6, 34, 60, 86, 112, 138 };
                        break;
                    case 33:
                        buffer3 = new byte[] { 6, 30, 58, 86, 114, 142 };
                        break;
                    case 34:
                        buffer3 = new byte[] { 6, 34, 62, 90, 118, 146 };
                        break;
                    case 35:
                        buffer3 = new byte[] { 6, 30, 54, 78, 102, 126, 150 };
                        break;
                    case 36:
                        buffer3 = new byte[] { 6, 24, 50, 76, 102, 128, 154 };
                        break;
                    case 37:
                        buffer3 = new byte[] { 6, 28, 54, 80, 106, 132, 158 };
                        break;
                    case 38:
                        buffer3 = new byte[] { 6, 32, 58, 84, 110, 136, 162 };
                        break;
                    case 39:
                        buffer3 = new byte[] { 6, 26, 54, 82, 110, 138, 166 };
                        break;
                    case 40:
                        buffer3 = new byte[] { 6, 30, 58, 86, 114, 142, 170 };
                        break;
                    default:
                        buffer3 = new byte[1];
                        break;
                }
                int num5 = pSymbolSize * (pSymbolSize + 1);
                byte[] buffer4 = new byte[num5 - 1 + 1 - 1 + 1];
                int num6 = buffer4.Length - 1;
                for (int i = 0; i <= num6; i++)
                {
                    buffer4[i] = 0;
                }
                //int num8=0;
                //int num9=0;
                //int num7 = CQRCode.QRCodeGet1DimensionAddress(num8, num9, pSymbolSize);
                int num10 = buffer2.Length - 1;
                for (int j = 0; j <= num10; j++)
                {
                    int num11 = buffer2.Length - 1;
                    for (int k = 0; k <= num11; k++)
                    {
                        int pX = buffer2[j];
                        int pY = buffer2[k];
                        bool flag = !(j == buffer2.Length - 1 & k == buffer2.Length - 1);
                        if (flag)
                        {
                            buffer4[QRCodeGet1DimensionAddress(pX + 1, pY - 1, pSymbolSize)] = 3;
                            buffer4[QRCodeGet1DimensionAddress(pX, pY - 1, pSymbolSize)] = 3;
                            buffer4[QRCodeGet1DimensionAddress(pX - 1, pY - 1, pSymbolSize)] = 3;
                            buffer4[QRCodeGet1DimensionAddress(pX + 1, pY, pSymbolSize)] = 3;
                            buffer4[QRCodeGet1DimensionAddress(pX, pY, pSymbolSize)] = 3;
                            buffer4[QRCodeGet1DimensionAddress(pX - 1, pY, pSymbolSize)] = 3;
                            buffer4[QRCodeGet1DimensionAddress(pX + 1, pY + 1, pSymbolSize)] = 3;
                            buffer4[QRCodeGet1DimensionAddress(pX, pY + 1, pSymbolSize)] = 3;
                            buffer4[QRCodeGet1DimensionAddress(pX - 1, pY + 1, pSymbolSize)] = 3;
                            buffer4[QRCodeGet1DimensionAddress(pX + 3, pY - 3, pSymbolSize)] = 3;
                            buffer4[QRCodeGet1DimensionAddress(pX + 2, pY - 3, pSymbolSize)] = 3;
                            buffer4[QRCodeGet1DimensionAddress(pX + 1, pY - 3, pSymbolSize)] = 3;
                            buffer4[QRCodeGet1DimensionAddress(pX, pY - 3, pSymbolSize)] = 3;
                            buffer4[QRCodeGet1DimensionAddress(pX - 1, pY - 3, pSymbolSize)] = 3;
                            buffer4[QRCodeGet1DimensionAddress(pX - 2, pY - 3, pSymbolSize)] = 3;
                            buffer4[QRCodeGet1DimensionAddress(pX - 3, pY - 3, pSymbolSize)] = 3;
                            buffer4[QRCodeGet1DimensionAddress(pX + 3, pY + 3, pSymbolSize)] = 3;
                            buffer4[QRCodeGet1DimensionAddress(pX + 2, pY + 3, pSymbolSize)] = 3;
                            buffer4[QRCodeGet1DimensionAddress(pX + 1, pY + 3, pSymbolSize)] = 3;
                            buffer4[QRCodeGet1DimensionAddress(pX, pY + 3, pSymbolSize)] = 3;
                            buffer4[QRCodeGet1DimensionAddress(pX - 1, pY + 3, pSymbolSize)] = 3;
                            buffer4[QRCodeGet1DimensionAddress(pX - 2, pY + 3, pSymbolSize)] = 3;
                            buffer4[QRCodeGet1DimensionAddress(pX - 3, pY + 3, pSymbolSize)] = 3;
                            buffer4[QRCodeGet1DimensionAddress(pX - 3, pY - 2, pSymbolSize)] = 3;
                            buffer4[QRCodeGet1DimensionAddress(pX - 3, pY - 1, pSymbolSize)] = 3;
                            buffer4[QRCodeGet1DimensionAddress(pX - 3, pY, pSymbolSize)] = 3;
                            buffer4[QRCodeGet1DimensionAddress(pX - 3, pY + 1, pSymbolSize)] = 3;
                            buffer4[QRCodeGet1DimensionAddress(pX - 3, pY + 2, pSymbolSize)] = 3;
                            buffer4[QRCodeGet1DimensionAddress(pX + 3, pY - 2, pSymbolSize)] = 3;
                            buffer4[QRCodeGet1DimensionAddress(pX + 3, pY - 1, pSymbolSize)] = 3;
                            buffer4[QRCodeGet1DimensionAddress(pX + 3, pY, pSymbolSize)] = 3;
                            buffer4[QRCodeGet1DimensionAddress(pX + 3, pY + 1, pSymbolSize)] = 3;
                            buffer4[QRCodeGet1DimensionAddress(pX + 3, pY + 2, pSymbolSize)] = 3;
                            buffer4[QRCodeGet1DimensionAddress(pX + 2, pY - 2, pSymbolSize)] = 2;
                            buffer4[QRCodeGet1DimensionAddress(pX + 1, pY - 2, pSymbolSize)] = 2;
                            buffer4[QRCodeGet1DimensionAddress(pX, pY - 2, pSymbolSize)] = 2;
                            buffer4[QRCodeGet1DimensionAddress(pX - 1, pY - 2, pSymbolSize)] = 2;
                            buffer4[QRCodeGet1DimensionAddress(pX - 2, pY - 2, pSymbolSize)] = 2;
                            buffer4[QRCodeGet1DimensionAddress(pX + 2, pY + 2, pSymbolSize)] = 2;
                            buffer4[QRCodeGet1DimensionAddress(pX + 1, pY + 2, pSymbolSize)] = 2;
                            buffer4[QRCodeGet1DimensionAddress(pX, pY + 2, pSymbolSize)] = 2;
                            buffer4[QRCodeGet1DimensionAddress(pX - 1, pY + 2, pSymbolSize)] = 2;
                            buffer4[QRCodeGet1DimensionAddress(pX - 2, pY + 2, pSymbolSize)] = 2;
                            buffer4[QRCodeGet1DimensionAddress(pX - 2, pY - 1, pSymbolSize)] = 2;
                            buffer4[QRCodeGet1DimensionAddress(pX - 2, pY, pSymbolSize)] = 2;
                            buffer4[QRCodeGet1DimensionAddress(pX - 2, pY + 1, pSymbolSize)] = 2;
                            buffer4[QRCodeGet1DimensionAddress(pX + 2, pY - 1, pSymbolSize)] = 2;
                            buffer4[QRCodeGet1DimensionAddress(pX + 2, pY, pSymbolSize)] = 2;
                            buffer4[QRCodeGet1DimensionAddress(pX + 2, pY + 1, pSymbolSize)] = 2;
                            bool flag2 = j == 0 & k == 0;
                            if (flag2)
                            {
                                int num12 = -3;
                                do
                                {
                                    buffer4[QRCodeGet1DimensionAddress(pX + 4, pY + num12, pSymbolSize)] = 8;
                                    num12++;
                                }
                                while (num12 <= 4);
                                int num13 = -3;
                                do
                                {
                                    buffer4[QRCodeGet1DimensionAddress(pX + num13, pY + 4, pSymbolSize)] = 8;
                                    num13++;
                                }
                                while (num13 <= 4);
                            }
                            bool flag3 = j == 0 & k == 1;
                            if (flag3)
                            {
                                int num14 = -4;
                                do
                                {
                                    buffer4[QRCodeGet1DimensionAddress(pX + 4, pY + num14, pSymbolSize)] = 8;
                                    num14++;
                                }
                                while (num14 <= 3);
                                int num15 = -3;
                                do
                                {
                                    buffer4[QRCodeGet1DimensionAddress(pX - num15, pY - 4, pSymbolSize)] = 8;
                                    num15++;
                                }
                                while (num15 <= 4);
                            }
                            bool flag4 = j == 1 & k == 0;
                            if (flag4)
                            {
                                int num16 = -3;
                                do
                                {
                                    buffer4[QRCodeGet1DimensionAddress(pX - 4, pY + num16, pSymbolSize)] = 8;
                                    num16++;
                                }
                                while (num16 <= 4);
                                int num17 = -4;
                                do
                                {
                                    buffer4[QRCodeGet1DimensionAddress(pX + num17, pY + 4, pSymbolSize)] = 8;
                                    num17++;
                                }
                                while (num17 <= 3);
                            }
                        }
                    }
                }
                int num18 = buffer3.Length - 1;
                for (int l = 0; l <= num18; l++)
                {
                    int num19 = buffer3.Length - 1;
                    for (int num20 = 0; num20 <= num19; num20++)
                    {
                        int num21 = buffer3[l];
                        int num22 = buffer3[num20];
                        bool flag5 = !(l == 0 & num20 == 0 | l == 0 & num20 == buffer3.Length - 1 | num20 == 0 & l == buffer3.Length - 1);
                        if (flag5)
                        {
                            buffer4[QRCodeGet1DimensionAddress(num21, num22, pSymbolSize)] = 5;
                            buffer4[QRCodeGet1DimensionAddress(num21 + 2, num22 - 2, pSymbolSize)] = 5;
                            buffer4[QRCodeGet1DimensionAddress(num21 + 1, num22 - 2, pSymbolSize)] = 5;
                            buffer4[QRCodeGet1DimensionAddress(num21, num22 - 2, pSymbolSize)] = 5;
                            buffer4[QRCodeGet1DimensionAddress(num21 - 1, num22 - 2, pSymbolSize)] = 5;
                            buffer4[QRCodeGet1DimensionAddress(num21 - 2, num22 - 2, pSymbolSize)] = 5;
                            buffer4[QRCodeGet1DimensionAddress(num21 + 2, num22 + 2, pSymbolSize)] = 5;
                            buffer4[QRCodeGet1DimensionAddress(num21 + 1, num22 + 2, pSymbolSize)] = 5;
                            buffer4[QRCodeGet1DimensionAddress(num21, num22 + 2, pSymbolSize)] = 5;
                            buffer4[QRCodeGet1DimensionAddress(num21 - 1, num22 + 2, pSymbolSize)] = 5;
                            buffer4[QRCodeGet1DimensionAddress(num21 - 2, num22 + 2, pSymbolSize)] = 5;
                            buffer4[QRCodeGet1DimensionAddress(num21 - 2, num22 - 1, pSymbolSize)] = 5;
                            buffer4[QRCodeGet1DimensionAddress(num21 - 2, num22, pSymbolSize)] = 5;
                            buffer4[QRCodeGet1DimensionAddress(num21 - 2, num22 + 1, pSymbolSize)] = 5;
                            buffer4[QRCodeGet1DimensionAddress(num21 + 2, num22 - 1, pSymbolSize)] = 5;
                            buffer4[QRCodeGet1DimensionAddress(num21 + 2, num22, pSymbolSize)] = 5;
                            buffer4[QRCodeGet1DimensionAddress(num21 + 2, num22 + 1, pSymbolSize)] = 5;
                            buffer4[QRCodeGet1DimensionAddress(num21 + 1, num22 - 1, pSymbolSize)] = 4;
                            buffer4[QRCodeGet1DimensionAddress(num21, num22 - 1, pSymbolSize)] = 4;
                            buffer4[QRCodeGet1DimensionAddress(num21 - 1, num22 - 1, pSymbolSize)] = 4;
                            buffer4[QRCodeGet1DimensionAddress(num21 + 1, num22 + 1, pSymbolSize)] = 4;
                            buffer4[QRCodeGet1DimensionAddress(num21, num22 + 1, pSymbolSize)] = 4;
                            buffer4[QRCodeGet1DimensionAddress(num21 - 1, num22 + 1, pSymbolSize)] = 4;
                            buffer4[QRCodeGet1DimensionAddress(num21 - 1, num22, pSymbolSize)] = 4;
                            buffer4[QRCodeGet1DimensionAddress(num21 + 1, num22, pSymbolSize)] = 4;
                        }
                    }
                }
                int num23 = pSymbolSize - 9;
                for (int m = 8; m <= num23; m += 2)
                {
                    buffer4[QRCodeGet1DimensionAddress(m, 6, pSymbolSize)] = (byte)(17 | buffer4[QRCodeGet1DimensionAddress(m, 6, pSymbolSize)]);
                    buffer4[QRCodeGet1DimensionAddress(6, m, pSymbolSize)] = (byte)(17 | buffer4[QRCodeGet1DimensionAddress(6, m, pSymbolSize)]);
                    bool flag6 = m != pSymbolSize - 9;
                    if (flag6)
                    {
                        buffer4[QRCodeGet1DimensionAddress(m + 1, 6, pSymbolSize)] = (byte)(16 | buffer4[QRCodeGet1DimensionAddress(m + 1, 6, pSymbolSize)]);
                        buffer4[QRCodeGet1DimensionAddress(6, m + 1, pSymbolSize)] = (byte)(16 | buffer4[QRCodeGet1DimensionAddress(6, m + 1, pSymbolSize)]);
                    }
                }
                buffer4[QRCodeGet1DimensionAddress(8, pSymbolSize - 8, pSymbolSize)] = 129;
                bool flag7 = pVersion >= 7;
                if (flag7)
                {
                    int[] numArray = new int[] { 31892, 34236, 39577, 42195, 48118, 51042, 55367, 58893, 63784, 68472, 70749, 76311, 79154, 84390, 87683, 92361, 96236, 102084, 102881, 110507, 110734, 117786, 119615, 126325, 127568, 133589, 136944, 141498, 145311, 150283, 152622, 158308, 161089, 167017 };
                    int num24 = numArray[pVersion - 7];
                    int num25 = 0;
                    do
                    {
                        int num26 = 0;
                        do
                        {
                            int num27 = num24 & 1;
                            bool flag8 = num27 == 1;
                            if (flag8)
                            {
                                buffer4[QRCodeGet1DimensionAddress(pSymbolSize - 11 + num26, num25, pSymbolSize)] = (byte)(33 | buffer4[QRCodeGet1DimensionAddress(pSymbolSize - 11 + num26, num25, pSymbolSize)]);
                                buffer4[QRCodeGet1DimensionAddress(num25, pSymbolSize - 11 + num26, pSymbolSize)] = (byte)(33 | buffer4[QRCodeGet1DimensionAddress(num25, pSymbolSize - 11 + num26, pSymbolSize)]);
                            }
                            else
                            {
                                buffer4[QRCodeGet1DimensionAddress(pSymbolSize - 11 + num26, num25, pSymbolSize)] = (byte)(32 | buffer4[QRCodeGet1DimensionAddress(pSymbolSize - 11 + num26, num25, pSymbolSize)]);
                                buffer4[QRCodeGet1DimensionAddress(num25, pSymbolSize - 11 + num26, pSymbolSize)] = (byte)(32 | buffer4[QRCodeGet1DimensionAddress(num25, pSymbolSize - 11 + num26, pSymbolSize)]);
                            }
                            num24 >>= 1;
                            num26++;
                        }
                        while (num26 <= 2);
                        num25++;
                    }
                    while (num25 <= 5);
                }
                lFormatSecondX = QRCodeGetFormatX((int)lQRInquireVersion);
                lFormatSecondY = QRCodeGetFormatY((int)lQRInquireVersion);
                int index = 0;
                do
                {
                    buffer4[QRCodeGet1DimensionAddress(lFormatFirstX[index], lFormatFirstY[index], pSymbolSize)] = (byte)(64 | buffer4[QRCodeGet1DimensionAddress(lFormatFirstX[index], lFormatFirstY[index], pSymbolSize)]);
                    buffer4[QRCodeGet1DimensionAddress(lFormatSecondX[index], lFormatSecondY[index], pSymbolSize)] = (byte)(64 | buffer4[QRCodeGet1DimensionAddress(lFormatSecondX[index], lFormatSecondY[index], pSymbolSize)]);
                    index++;
                }
                while (index <= 14);
                return buffer4;
            }
        }

        private byte[] QRCodeGetTotalData(byte[] pInputData, byte pEcc, int pData, int pTotal)
        {
            checked
            {
                byte[,] buffer5 = new byte[256, (pEcc - 1 + 1 - 1 + 1)];
                int num2 = gDataWords[(int)QRSetECCRate, lQRInquireVersion - QRVersions.Ver01];
                int num3 = gExtraDataWords[(int)QRSetECCRate, lQRInquireVersion - QRVersions.Ver01];
                float num4 = gECCWords[(int)QRSetECCRate, lQRInquireVersion - QRVersions.Ver01];
                int num5 = gRSBlockCount[(int)QRSetECCRate, lQRInquireVersion - QRVersions.Ver01];
                byte[] buffer6 = new byte[] { 1, 2, 4, 8, 16, 32, 64, 128, 29, 58, 116, 232, 205, 135, 19, 38, 76, 152, 45, 90, 180, 117, 234, 201, 143, 3, 6, 12, 24, 48, 96, 192, 157, 39, 78, 156, 37, 74, 148, 53, 106, 212, 181, 119, 238, 193, 159, 35, 70, 140, 5, 10, 20, 40, 80, 160, 93, 186, 105, 210, 185, 111, 222, 161, 95, 190, 97, 194, 153, 47, 94, 188, 101, 202, 137, 15, 30, 60, 120, 240, 253, 231, 211, 187, 107, 214, 177, 127, 254, 225, 223, 163, 91, 182, 113, 226, 217, 175, 67, 134, 17, 34, 68, 136, 13, 26, 52, 104, 208, 189, 103, 206, 129, 31, 62, 124, 248, 237, 199, 147, 59, 118, 236, 197, 151, 51, 102, 204, 133, 23, 46, 92, 184, 109, 218, 169, 79, 158, 33, 66, 132, 21, 42, 84, 168, 77, 154, 41, 82, 164, 85, 170, 73, 146, 57, 114, 228, 213, 183, 115, 230, 209, 191, 99, 198, 145, 63, 126, 252, 229, 215, 179, 123, 246, 241, 255, 227, 219, 171, 75, 150, 49, 98, 196, 149, 55, 110, 220, 165, 87, 174, 65, 130, 25, 50, 100, 200, 141, 7, 14, 28, 56, 112, 224, 221, 167, 83, 166, 81, 162, 89, 178, 121, 242, 249, 239, 195, 155, 43, 86, 172, 69, 138, 9, 18, 36, 72, 144, 61, 122, 244, 245, 247, 243, 251, 235, 203, 139, 11, 22, 44, 88, 176, 125, 250, 233, 207, 131, 27, 54, 108, 216, 173, 71, 142, 1 };
                byte[] buffer7 = new byte[]
                {
                    0,
                    0,
                    1,
                    25,
                    2,
                    50,
                    26,
                    198,
                    3,
                    223,
                    51,
                    238,
                    27,
                    104,
                    199,
                    75,
                    4,
                    100,
                    224,
                    14,
                    52,
                    141,
                    239,
                    129,
                    28,
                    193,
                    105,
                    248,
                    200,
                    8,
                    76,
                    113,
                    5,
                    138,
                    101,
                    47,
                    225,
                    36,
                    15,
                    33,
                    53,
                    147,
                    142,
                    218,
                    240,
                    18,
                    130,
                    69,
                    29,
                    181,
                    194,
                    125,
                    106,
                    39,
                    249,
                    185,
                    201,
                    154,
                    9,
                    120,
                    77,
                    228,
                    114,
                    166,
                    6,
                    191,
                    139,
                    98,
                    102,
                    221,
                    48,
                    253,
                    226,
                    152,
                    37,
                    179,
                    16,
                    145,
                    34,
                    136,
                    54,
                    208,
                    148,
                    206,
                    143,
                    150,
                    219,
                    189,
                    241,
                    210,
                    19,
                    92,
                    131,
                    56,
                    70,
                    64,
                    30,
                    66,
                    182,
                    163,
                    195,
                    72,
                    126,
                    110,
                    107,
                    58,
                    40,
                    84,
                    250,
                    133,
                    186,
                    61,
                    202,
                    94,
                    155,
                    159,
                    10,
                    21,
                    121,
                    43,
                    78,
                    212,
                    229,
                    172,
                    115,
                    243,
                    167,
                    87,
                    7,
                    112,
                    192,
                    247,
                    140,
                    128,
                    99,
                    13,
                    103,
                    74,
                    222,
                    237,
                    49,
                    197,
                    254,
                    24,
                    227,
                    165,
                    153,
                    119,
                    38,
                    184,
                    180,
                    124,
                    17,
                    68,
                    146,
                    217,
                    35,
                    32,
                    137,
                    46,
                    55,
                    63,
                    209,
                    91,
                    149,
                    188,
                    207,
                    205,
                    144,
                    135,
                    151,
                    178,
                    220,
                    252,
                    190,
                    97,
                    242,
                    86,
                    211,
                    171,
                    20,
                    42,
                    93,
                    158,
                    132,
                    60,
                    57,
                    83,
                    71,
                    109,
                    65,
                    162,
                    31,
                    45,
                    67,
                    216,
                    183,
                    123,
                    164,
                    118,
                    196,
                    23,
                    73,
                    236,
                    127,
                    12,
                    111,
                    246,
                    108,
                    161,
                    59,
                    82,
                    41,
                    157,
                    85,
                    170,
                    251,
                    96,
                    134,
                    177,
                    187,
                    204,
                    62,
                    90,
                    203,
                    89,
                    95,
                    176,
                    156,
                    169,
                    160,
                    81,
                    11,
                    245,
                    22,
                    235,
                    122,
                    117,
                    44,
                    215,
                    79,
                    174,
                    213,
                    233,
                    230,
                    231,
                    173,
                    232,
                    116,
                    214,
                    244,
                    234,
                    168,
                    80,
                    88,
                    175
                };
                byte[] buffer8 = new byte[(pEcc - 1 + 1 - 1 + 1)];
                switch (pEcc)
                {
                    case 7:
                        buffer8 = new byte[]
                        {
                        127,
                        122,
                        154,
                        164,
                        11,
                        68,
                        117
                        };
                        break;
                    case 10:
                        buffer8 = new byte[]
                        {
                        216,
                        194,
                        159,
                        111,
                        199,
                        94,
                        95,
                        113,
                        157,
                        193
                        };
                        break;
                    case 13:
                        buffer8 = new byte[]
                        {
                        137,
                        73,
                        227,
                        17,
                        177,
                        17,
                        52,
                        13,
                        46,
                        43,
                        83,
                        132,
                        120
                        };
                        break;
                    case 15:
                        buffer8 = new byte[]
                        {
                        29,
                        196,
                        111,
                        163,
                        112,
                        74,
                        10,
                        105,
                        105,
                        139,
                        132,
                        151,
                        32,
                        134,
                        26
                        };
                        break;
                    case 16:
                        buffer8 = new byte[]
                        {
                        59,
                        13,
                        104,
                        189,
                        68,
                        209,
                        30,
                        8,
                        163,
                        65,
                        41,
                        229,
                        98,
                        50,
                        36,
                        59
                        };
                        break;
                    case 17:
                        buffer8 = new byte[]
                        {
                        119,
                        66,
                        83,
                        120,
                        119,
                        22,
                        197,
                        83,
                        249,
                        41,
                        143,
                        134,
                        85,
                        53,
                        125,
                        99,
                        79
                        };
                        break;
                    case 18:
                        buffer8 = new byte[]
                        {
                        239,
                        251,
                        183,
                        113,
                        149,
                        175,
                        199,
                        215,
                        240,
                        220,
                        73,
                        82,
                        173,
                        75,
                        32,
                        67,
                        217,
                        146
                        };
                        break;
                    case 20:
                        buffer8 = new byte[]
                        {
                        152,
                        185,
                        240,
                        5,
                        111,
                        99,
                        6,
                        220,
                        112,
                        150,
                        69,
                        36,
                        187,
                        22,
                        228,
                        198,
                        121,
                        121,
                        165,
                        174
                        };
                        break;
                    case 22:
                        buffer8 = new byte[]
                        {
                        89,
                        179,
                        131,
                        176,
                        182,
                        244,
                        19,
                        189,
                        69,
                        40,
                        28,
                        137,
                        29,
                        123,
                        67,
                        253,
                        86,
                        218,
                        230,
                        26,
                        145,
                        245
                        };
                        break;
                    case 24:
                        buffer8 = new byte[]
                        {
                        122,
                        118,
                        169,
                        70,
                        178,
                        237,
                        216,
                        102,
                        115,
                        150,
                        229,
                        73,
                        130,
                        72,
                        61,
                        43,
                        206,
                        1,
                        237,
                        247,
                        127,
                        217,
                        144,
                        117
                        };
                        break;
                    case 26:
                        buffer8 = new byte[]
                        {
                        246,
                        51,
                        183,
                        4,
                        136,
                        98,
                        199,
                        152,
                        77,
                        56,
                        206,
                        24,
                        145,
                        40,
                        209,
                        117,
                        233,
                        42,
                        135,
                        68,
                        70,
                        144,
                        146,
                        77,
                        43,
                        94
                        };
                        break;
                    case 28:
                        buffer8 = new byte[]
                        {
                        252,
                        9,
                        28,
                        13,
                        18,
                        251,
                        208,
                        150,
                        103,
                        174,
                        100,
                        41,
                        167,
                        12,
                        247,
                        56,
                        117,
                        119,
                        233,
                        127,
                        181,
                        100,
                        121,
                        147,
                        176,
                        74,
                        58,
                        197
                        };
                        break;
                    case 30:
                        buffer8 = new byte[]
                        {
                        212,
                        246,
                        77,
                        73,
                        195,
                        192,
                        75,
                        98,
                        5,
                        70,
                        103,
                        177,
                        22,
                        217,
                        138,
                        51,
                        181,
                        246,
                        72,
                        25,
                        18,
                        46,
                        228,
                        74,
                        216,
                        195,
                        11,
                        106,
                        130,
                        150
                        };
                        break;
                }
                int num6 = buffer8.Length - 1;
                for (int i = 0; i <= num6; i++)
                {
                    int num7 = buffer8[i];
                    num7 = buffer7[num7];
                    int num8 = 0;
                    do
                    {
                        int num9 = (num7 + buffer7[num8]) % 255;
                        int num10 = buffer6[num9];
                        buffer5[num8, i] = (byte)num10;
                        num8++;
                    }
                    while (num8 <= 255);
                }
                int num11 = 0;
                int num12 = 0;
                lRSBlock = new byte[num5 - 1 + 1 - 1 + 1];
                int num13 = num5 - 1;
                for (int j = 0; j <= num13; j++)
                {
                    bool flag = j >= num5 - num3;
                    if (flag)
                    {
                        lRSBlock[j] = (byte)Math.Round((double)unchecked(num2 + num4 + 1f));
                    }
                    else
                    {
                        lRSBlock[j] = (byte)Math.Round((double)unchecked(num2 + num4));
                    }
                }
                byte[][] bufferArray = new byte[lRSBlock.Length - 1 + 1 - 1 + 1][];
                byte[] destinationArray = new byte[pTotal - 1 + 1 - 1 + 1];
                Array.Copy(pInputData, 0, destinationArray, 0, pInputData.Length);
                int num19 = lRSBlock.Length - 1;
                for (int index = 0; index <= num19; index++)
                {
                    int num14 = lRSBlock.Length - 1;
                    for (int k = 0; k <= num14; k++)
                    {
                        bufferArray[k] = new byte[(unchecked(lRSBlock[index] - pEcc) + 1 - 1 + 1)];
                    }
                }
                int num20 = pData - 1;
                for (int index = 0; index <= num20; index++)
                {
                    bufferArray[num12][num11] = pInputData[index];
                    num11++;
                    bool flag2 = num11 >= unchecked(lRSBlock[num12] - pEcc);
                    if (flag2)
                    {
                        num11 = 0;
                        num12++;
                    }
                }
                int num21 = lRSBlock.Length - 1;
                for (num12 = 0; num12 <= num21; num12++)
                {
                    byte[] sourceArray = (byte[])bufferArray[num12].Clone();
                    int num15 = lRSBlock[num12];
                    int num16 = num15 - pEcc;
                    for (num11 = num16; num11 > 0; num11--)
                    {
                        byte num17 = sourceArray[0];
                        bool flag3 = num17 > 0;
                        if (flag3)
                        {
                            byte[] buffer9 = new byte[sourceArray.Length - 1 + 1 - 1 + 1];
                            Array.Copy(sourceArray, 1, buffer9, 0, sourceArray.Length - 1);
                            byte[] buffer10 = new byte[buffer5.GetLength(1) + 1 - 1 + 1];
                            int num18 = buffer5.GetLength(1) - 1;
                            for (int l = 0; l <= num18; l++)
                            {
                                buffer10[l] = buffer5[num17, l];
                            }
                            sourceArray = QRCodeGetByteData(buffer9, buffer10);
                        }
                        else
                        {
                            bool flag4 = pEcc < sourceArray.Length;
                            if (flag4)
                            {
                                byte[] buffer11 = new byte[sourceArray.Length - 1 - 1 + 1 - 1 + 1];
                                Array.Copy(sourceArray, 1, buffer11, 0, sourceArray.Length - 1);
                                sourceArray = (byte[])buffer11.Clone();
                            }
                            else
                            {
                                byte[] buffer12 = new byte[(pEcc - 1 + 1 - 1 + 1)];
                                Array.Copy(sourceArray, 1, buffer12, 0, sourceArray.Length - 1);
                                buffer12[pEcc - 1] = 0;
                                sourceArray = (byte[])buffer12.Clone();
                            }
                        }
                    }
                    Array.Copy(sourceArray, 0, destinationArray, pInputData.Length + num12 * pEcc, pEcc);
                }
                return destinationArray;
            }
        }

        /// <summary>
        /// 刷新lQRInquireNumericBits/lQRInquireAlphaNumericBits/lQRInquireBinaryBits
        /// </summary>
        /// <param name="QRText"></param>
        /// <remarks></remarks>
        // Token: 0x060008F6 RID: 2294 RVA: 0x000396CC File Offset: 0x000378CC
        private void QRCodeInquireBits(string QRText)
        {
            bool flag3 = true;
            bool flag4 = true;
            int length = QRText.Length;
            checked
            {
                int num3 = length - 1;
                for (int i = 0; i <= num3; i++)
                {
                    bool flag5 = !CheckTextCharNumeric(QRText[i]);
                    if (flag5)
                    {
                        flag3 = false;
                    }
                    bool flag6 = !CheckTextCharAlphaNumeric(QRText[i]);
                    if (flag6)
                    {
                        flag4 = false;
                    }
                }
                bool flag7 = flag3;
                if (flag7)
                {
                    switch (length % 3)
                    {
                        case 0:
                            lQRInquireNumericBits = length / 3 * 10;
                            break;
                        case 1:
                            lQRInquireNumericBits = length / 3 * 10 + 4;
                            break;
                        case 2:
                            lQRInquireNumericBits = length / 3 * 10 + 7;
                            break;
                    }
                }
                else
                {
                    lQRInquireNumericBits = 0;
                }
                bool flag8 = flag4;
                if (flag8)
                {
                    int num4 = length % 2;
                    if (num4 != 0)
                    {
                        if (num4 == 1)
                        {
                            lQRInquireAlphaNumericBits = length / 2 * 11 + 6;
                        }
                    }
                    else
                    {
                        lQRInquireAlphaNumericBits = length / 2 * 11;
                    }
                }
                else
                {
                    lQRInquireAlphaNumericBits = 0;
                }
                byte[] bytes = Encoding.UTF8.GetBytes(QRText);
                lQRInquireBinaryBits = bytes.Length * 8;
            }
        }

        private QRTextTypes QRCodeSetInquireTextType()
        {
            int qRInquireBinaryBits = QRInquireBinaryBits;
            QRTextTypes binary = QRTextTypes.Binary;
            bool flag = QRInquireNumericBits > 0 && qRInquireBinaryBits > QRInquireNumericBits;
            if (flag)
            {
                qRInquireBinaryBits = QRInquireNumericBits;
                binary = QRTextTypes.Numeric;
            }
            bool flag2 = QRInquireAlphaNumericBits > 0 && qRInquireBinaryBits > QRInquireAlphaNumericBits;
            if (flag2)
            {
                binary = QRTextTypes.AlphaNumeric;
            }
            bool flag3 = QRSetTextType == QRTextTypes.Numeric && QRInquireNumericBits > 0;
            QRTextTypes QRCodeSetInquireTextType;
            if (flag3)
            {
                QRCodeSetInquireTextType = QRTextTypes.Numeric;
            }
            else
            {
                bool flag4 = QRSetTextType == QRTextTypes.AlphaNumeric && QRInquireAlphaNumericBits > 0;
                if (flag4)
                {
                    QRCodeSetInquireTextType = QRTextTypes.AlphaNumeric;
                }
                else
                {
                    bool flag5 = QRSetTextType == QRTextTypes.Binary && QRInquireBinaryBits > 0;
                    if (flag5)
                    {
                        QRCodeSetInquireTextType = QRTextTypes.Binary;
                    }
                    else
                    {
                        lQRInquireTextType = binary;
                        QRCodeSetInquireTextType = binary;
                    }
                }
            }
            return QRCodeSetInquireTextType;
        }

        private byte[] QRCodeTransRSBlock(byte[] pDeployData)
        {
            checked
            {
                int num2 = gDataWords[(int)QRSetECCRate, lQRInquireVersion - QRVersions.Ver01];
                int num3 = gExtraDataWords[(int)QRSetECCRate, lQRInquireVersion - QRVersions.Ver01];
                float num4 = gECCWords[(int)QRSetECCRate, lQRInquireVersion - QRVersions.Ver01];
                int num5 = gRSBlockCount[(int)QRSetECCRate, lQRInquireVersion - QRVersions.Ver01];
                byte[] buffer = new byte[pDeployData.Length - 1 + 1 - 1 + 1];
                int num6 = 0;
                int[] numArray = new int[129];
                int num7 = 0;
                int num8 = num2 - 1;
                for (int i = 0; i <= num8; i++)
                {
                    int num9 = num5 - 1;
                    for (int j = 0; j <= num9; j++)
                    {
                        bool flag = j > num5 - num3;
                        int num10;
                        if (flag)
                        {
                            num10 = j - (num5 - num3);
                            bool flag2 = i == 0;
                            if (flag2)
                            {
                                numArray[num7] = i + j * num2 + num10 - 1;
                                num7++;
                            }
                        }
                        else
                        {
                            num10 = 0;
                        }
                        int num11 = 0;
                        do
                        {
                            int index = (i + j * num2 + num10) * 8 + num11;
                            buffer[index] = pDeployData[num6];
                            num6++;
                            num11++;
                        }
                        while (num11 <= 7);
                    }
                }
                bool flag3 = num3 > 0;
                if (flag3)
                {
                    numArray[num7] = num2 * num5 + num3 - 1;
                    num7++;
                }
                int num12 = num7 - 1;
                for (int k = 0; k <= num12; k++)
                {
                    int num13 = 0;
                    do
                    {
                        int index = numArray[k] * 8 + num13;
                        buffer[index] = pDeployData[num6];
                        num6++;
                        num13++;
                    }
                    while (num13 <= 7);
                }
                int num14 = num6;
                int num15 = (int)Math.Round((double)unchecked(num4 - 1f));
                for (int l = 0; l <= num15; l++)
                {
                    int num16 = num5 - 1;
                    for (int m = 0; m <= num16; m++)
                    {
                        int num17 = 0;
                        do
                        {
                            int index = (int)Math.Round((double)unchecked(num14 + (l + m * num4) * 8f + num17));
                            buffer[index] = pDeployData[num6];
                            num6++;
                            num17++;
                        }
                        while (num17 <= 7);
                    }
                }
                while (num6 <= pDeployData.Length - 1)
                {
                    buffer[num6] = pDeployData[num6];
                    num6++;
                }
                return buffer;
            }
        }

        private static byte QRGetAlphaNumericCode(string pInput)
        {
            bool flag = pInput.ToDouble() >= 48.0 & pInput.ToDouble() < 58.0;

            {
                byte QRGetAlphaNumericCode;
                if (flag)
                {
                    QRGetAlphaNumericCode = (byte)Math.Round(pInput.ToDouble() - 48.0);
                }
                else
                {
                    bool flag2 = pInput.ToDouble() >= 65.0 & pInput.ToDouble() < 91.0;
                    if (flag2)
                    {
                        QRGetAlphaNumericCode = (byte)Math.Round(pInput.ToDouble() - 55.0);
                    }
                    else
                    {
                        bool flag3 = pInput == "32";
                        if (flag3)
                        {
                            QRGetAlphaNumericCode = 36;
                        }
                        else
                        {
                            bool flag4 = pInput.CompareTo(36.ToString()) == 0;
                            if (flag4)
                            {
                                QRGetAlphaNumericCode = 37;
                            }
                            else
                            {
                                bool flag5 = pInput.CompareTo(37.ToString()) == 0;
                                if (flag5)
                                {
                                    QRGetAlphaNumericCode = 38;
                                }
                                else
                                {
                                    bool flag6 = pInput.CompareTo(42.ToString()) == 0;
                                    if (flag6)
                                    {
                                        QRGetAlphaNumericCode = 39;
                                    }
                                    else
                                    {
                                        bool flag7 = pInput.CompareTo(43.ToString()) == 0;
                                        if (flag7)
                                        {
                                            QRGetAlphaNumericCode = 40;
                                        }
                                        else
                                        {
                                            bool flag8 = pInput.CompareTo(45.ToString()) == 0;
                                            if (flag8)
                                            {
                                                QRGetAlphaNumericCode = 41;
                                            }
                                            else
                                            {
                                                bool flag9 = pInput.CompareTo(46.ToString()) == 0;
                                                if (flag9)
                                                {
                                                    QRGetAlphaNumericCode = 42;
                                                }
                                                else
                                                {
                                                    bool flag10 = pInput.CompareTo(47.ToString()) == 0;
                                                    if (flag10)
                                                    {
                                                        QRGetAlphaNumericCode = 43;
                                                    }
                                                    else
                                                    {
                                                        bool flag11 = pInput.CompareTo(58.ToString()) == 0;
                                                        if (flag11)
                                                        {
                                                            QRGetAlphaNumericCode = 44;
                                                        }
                                                        else
                                                        {
                                                            QRGetAlphaNumericCode = 0;
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                return QRGetAlphaNumericCode;
            }
        }

        /// <summary>
        /// 生成指定二维码文本的数据
        /// </summary>
        /// <param name="pTextData"></param>
        /// <param name="EncodingIsAscii"></param>
        /// <returns></returns>
        public byte[,] QRGetData(string pTextData, bool EncodingIsAscii = false)
        {
            int[] numArray4 = new int[] { 0, 26, 44, 70, 100, 134, 172, 196, 242, 292, 346, 404, 466, 532, 581, 655, 733, 815, 901, 991, 1085, 1156, 1258, 1364, 1474, 1588, 1706, 1828, 1921, 2051, 2185, 2323, 2465, 2611, 2761, 2876, 3034, 3196, 3362, 3532, 3706 };
            int[] numArray5 = new int[] { 0, 0, 7, 7, 7, 7, 7, 0, 0, 0, 0, 0, 0, 0, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 0, 0, 0, 0, 0, 0 };
            int[,] numArray6 = new int[,]
            {
                { 0,  152,  272,   440,   640,  864,  1088,  1248,  1552,  1856,  2192,  2592,  2960,  3424,  3688, 4184,  4712,  5176,  5768,  6360,  6888,  7456, 8048, 8752, 9392,  10208,  10960, 11744, 12248,  13048,  13880, 14744, 15640, 16568, 17528, 18448, 19472, 20528,  21616, 22496,  23648  },
                {  0,  128,  224,  352,  512,  688,   864,  992,   1232,   1456,   1728,  2032,  2320,  2672,  2920,  3320,  3624, 4056,  4504,  5016,  5352,  5712,  6256, 6880,   7312,  8000,  8496,   9024,   9544,  10136,  10984,  11640,  12328,  13048,  13800,  14496,  15312,  15936,  16816,  17728,  18672  },
                { 0,  104,  176,   272,   384,   496,   608,   704,   880,  1056,  1232,  1440,  1648,  1952,  2088,  2360,  2600,   2936,  3176,  3560,   3880,  4096,  4544, 4912,  5312,  5744,  6032,  6464,   6968,  7288,  7880,  8264,  8920,  9368,  9848, 10288,  10832, 11408,  12016, 12656, 13328 },
                {  0,   72,  128,  208,  288,  368,   480,  528,  688,   800,  976,  1120,   1264,   1440,  1576,  1784,  2024,  2264,  2504,   2728,   3080, 3248,  3536,  3712,  4112, 4304,  4768,   5024,   5288,   5608,  5960,  6344,   6760,  7208,  7688,  7888,  8432,  8768,    9136,   9776,  10208 }
            };
            string[] strArray = new string[]
            {
                "111011111000100",
                "111001011110011",
                "111110110101010",
                "111100010011101",
                "110011000101111",
                "110001100011000",
                "110110001000001",
                "110100101110110",
                "101010000010010",
                "101000100100101",
                "101111001111100",
                "101101101001011",
                "100010111111001",
                "100000011001110",
                "100111110010111",
                "100101010100000",
                "011010101011111",
                "011000001101000",
                "011111100110001",
                "011101000000110",
                "010010010110100",
                "010000110000011",
                "010111011011010",
                "010101111101101",
                "001011010001001",
                "001001110111110",
                "001110011100111",
                "001100111010000",
                "000011101100010",
                "000001001010101",
                "000110100001100",
                "000100000111011"
            };
            byte[] buffer = new byte[1];
            int index = 0;
            int num10 = 0;
            byte[] bytes;
            if (EncodingIsAscii)
            {
                bytes = Encoding.ASCII.GetBytes(pTextData);
            }
            else
            {
                bytes = Encoding.UTF8.GetBytes(pTextData);
            }
            int length = bytes.Length;
            QRCodeInquireBits(pTextData);
            lQRInquireTextType = QRCodeSetInquireTextType();
            checked
            {
                int[] numArray7 = new int[length + 32 - 1 + 1];
                byte[] buffer2 = new byte[length + 32 - 1 + 1];
                bool flag = length <= 0;
                byte[,] QRGetData;
                if (flag)
                {
                    QRGetData = new byte[1, 1];
                }
                else
                {
                    buffer2[index] = 4;
                    int num11 = 0;
                    switch (QRInquireTextType)
                    {
                        case QRTextTypes.Numeric:
                            {
                                buffer = new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4 };
                                numArray7[index] = 1;
                                index++;
                                numArray7[index] = length;
                                buffer2[index] = 10;
                                num11 = index;
                                index++;
                                int num12 = length - 1;
                                for (int num13 = 0; num13 <= num12; num13++)
                                {
                                    byte num14 = QRGetNumericCode(bytes[num13].ToString());
                                    bool flag2 = num13 % 3 == 0;
                                    if (flag2)
                                    {
                                        numArray7[index] = num14;
                                        buffer2[index] = 4;
                                    }
                                    else
                                    {
                                        numArray7[index] = numArray7[index] * 10 + num14;
                                        bool flag3 = num13 % 3 == 1;
                                        if (flag3)
                                        {
                                            buffer2[index] = 7;
                                        }
                                        else
                                        {
                                            buffer2[index] = 10;
                                            bool flag4 = num13 < length - 1;
                                            if (flag4)
                                            {
                                                index++;
                                            }
                                        }
                                    }
                                }
                                index++;
                                break;
                            }
                        case QRTextTypes.AlphaNumeric:
                            {
                                buffer = new byte[]
                                {
                            0,
                            0,
                            0,
                            0,
                            0,
                            0,
                            0,
                            0,
                            0,
                            0,
                            2,
                            2,
                            2,
                            2,
                            2,
                            2,
                            2,
                            2,
                            2,
                            2,
                            2,
                            2,
                            2,
                            2,
                            2,
                            2,
                            2,
                            4,
                            4,
                            4,
                            4,
                            4,
                            4,
                            4,
                            4,
                            4,
                            4,
                            4,
                            4,
                            4,
                            4
                                };
                                numArray7[index] = 2;
                                index++;
                                numArray7[index] = length;
                                buffer2[index] = 9;
                                num11 = index;
                                index++;
                                int num15 = length - 1;
                                for (int num16 = 0; num16 <= num15; num16++)
                                {
                                    byte num17 = QRGetAlphaNumericCode(bytes[num16].ToString());
                                    bool flag5 = num16 % 2 == 0;
                                    if (flag5)
                                    {
                                        numArray7[index] = num17;
                                        buffer2[index] = 6;
                                    }
                                    else
                                    {
                                        numArray7[index] = numArray7[index] * 45 + num17;
                                        buffer2[index] = 11;
                                        bool flag6 = num16 < length - 1;
                                        if (flag6)
                                        {
                                            index++;
                                        }
                                    }
                                }
                                index++;
                                break;
                            }
                        case QRTextTypes.Binary:
                            {
                                buffer = new byte[]
                                {
                            0,
                            0,
                            0,
                            0,
                            0,
                            0,
                            0,
                            0,
                            0,
                            0,
                            8,
                            8,
                            8,
                            8,
                            8,
                            8,
                            8,
                            8,
                            8,
                            8,
                            8,
                            8,
                            8,
                            8,
                            8,
                            8,
                            8,
                            8,
                            8,
                            8,
                            8,
                            8,
                            8,
                            8,
                            8,
                            8,
                            8,
                            8,
                            8,
                            8,
                            8
                                };
                                numArray7[index] = 4;
                                index++;
                                numArray7[index] = length;
                                buffer2[index] = 8;
                                num11 = index;
                                index++;
                                int num18 = length - 1;
                                for (int num19 = 0; num19 <= num18; num19++)
                                {
                                    numArray7[num19 + index] = bytes[num19] & byte.MaxValue;
                                    buffer2[num19 + index] = 8;
                                }
                                index += length;
                                break;
                            }
                    }
                    int num20 = 0;
                    int num21 = index - 1;
                    for (int i = 0; i <= num21; i++)
                    {
                        num20 += buffer2[i];
                    }
                    lQRInquireVersion = QRVersions.Ver01;
                    int num22 = 1;
                    for (; ; )
                    {
                        bool flag7 = numArray6[(int)QRSetECCRate, num22] >= num20 + buffer[(int)lQRInquireVersion];
                        if (flag7)
                        {
                            break;
                        }
                        lQRInquireVersion++;
                        num22++;
                        if (num22 > 40)
                        {
                            goto IL_4B8;
                        }
                    }
                    num10 = numArray6[(int)QRSetECCRate, num22];
                IL_4B8:
                    bool flag8 = lQRInquireVersion > QRVersions.Ver40;
                    if (flag8)
                    {
                        lQRInquireVersion = QRVersions.Automatic;
                        QRGetData = new byte[1, 1];
                    }
                    else
                    {
                        bool flag9 = lQRInquireVersion > QRVersions.Automatic;
                        if (flag9)
                        {
                            bool flag10 = lQRInquireVersion > QRSetVersion;
                            if (flag10)
                            {
                                num10 = numArray6[(int)QRSetECCRate, (int)lQRInquireVersion];
                            }
                            else
                            {
                                lQRInquireVersion = QRSetVersion;
                                num10 = numArray6[(int)QRSetECCRate, (int)lQRInquireVersion];
                            }
                        }
                        num20 += buffer[(int)lQRInquireVersion];
                        int num23 = num11;
                        int pTotal;
                        unchecked
                        {
                            buffer2[num23] += buffer[(int)lQRInquireVersion];
                            pTotal = numArray4[(int)lQRInquireVersion];
                        }
                        int num24 = numArray5[(int)lQRInquireVersion] + (pTotal << 3);
                        lFormatSecondX = QRCodeGetFormatX((int)lQRInquireVersion);
                        lFormatSecondY = QRCodeGetFormatY((int)lQRInquireVersion);
                        byte pEcc = (byte)gECCWords[(int)QRSetECCRate, lQRInquireVersion - QRVersions.Ver01];
                        int pMaxBytes = (int)Math.Round(num10 / 8.0);
                        int num25 = (int)QRVersions.Ver04 * (int)lQRInquireVersion + 17;
                        lQRInquireModuleSize = num25;
                        //int num26 = num25 * num25;
                        byte[] buffer3 = QRCodeGetSymbolData((int)lQRInquireVersion);
                        lDeployTableX = new byte[num24 + 1 - 1 + 1];
                        lDeployTableY = new byte[num24 + 1 - 1 + 1];
                        lDeployOrderX = new byte[num24 - 1 + 1 - 1 + 1];
                        lDeployOrderY = new byte[num24 - 1 + 1 - 1 + 1];
                        int num27 = 0;
                        for (int j = num25 - 1; j >= 3; j += -4)
                        {
                            for (int num28 = num25 - 1; num28 >= 0; num28 += -1)
                            {
                                int num29 = num28 * (num25 + 1) + j;
                                int num30 = buffer3[num29] & 254;
                                bool flag11 = num30 == 0;
                                if (flag11)
                                {
                                    lDeployTableX[num27] = (byte)j;
                                    lDeployTableY[num27] = (byte)num28;
                                    num27++;
                                }
                                num29 = num28 * (num25 + 1) + j - 1;
                                num30 = buffer3[num29] & 254;
                                bool flag12 = num30 == 0;
                                if (flag12)
                                {
                                    lDeployTableX[num27] = (byte)(j - 1);
                                    lDeployTableY[num27] = (byte)num28;
                                    num27++;
                                }
                            }
                            bool flag13 = j == 8;
                            if (flag13)
                            {
                                j = 7;
                            }
                            int num31 = num25 - 1;
                            for (int num32 = 0; num32 <= num31; num32++)
                            {
                                int num33 = num32 * (num25 + 1) + j - 2;
                                int num34 = buffer3[num33] & 254;
                                bool flag14 = num34 == 0;
                                if (flag14)
                                {
                                    lDeployTableX[num27] = (byte)(j - 2);
                                    lDeployTableY[num27] = (byte)num32;
                                    num27++;
                                }
                                num33 = num32 * (num25 + 1) + j - 1 - 2;
                                num34 = buffer3[num33] & 254;
                                bool flag15 = num34 == 0;
                                if (flag15)
                                {
                                    lDeployTableX[num27] = (byte)(j - 1 - 2);
                                    lDeployTableY[num27] = (byte)num32;
                                    num27++;
                                }
                            }
                        }
                        lDeployOrderX = QRCodeTransRSBlock(lDeployTableX);
                        lDeployOrderY = QRCodeTransRSBlock(lDeployTableY);
                        bool flag16 = num20 <= num10 - 4;
                        if (flag16)
                        {
                            numArray7[index] = 0;
                            buffer2[index] = 4;
                        }
                        else
                        {
                            bool flag17 = num20 < num10;
                            if (flag17)
                            {
                                numArray7[index] = 0;
                                buffer2[index] = (byte)(num10 - num20);
                            }
                        }
                        byte[] pInputData = QRCodeGet8BitData(numArray7, buffer2, pMaxBytes);
                        byte[] buffer4 = QRCodeGetTotalData(pInputData, pEcc, pMaxBytes, pTotal);
                        byte[,] pModuleData = new byte[num25 - 1 + 1 - 1 + 1, num25 - 1 + 1 - 1 + 1];
                        int num35 = num25 - 1;
                        for (int k = 0; k <= num35; k++)
                        {
                            int num36 = num25 - 1;
                            for (int num37 = 0; num37 <= num36; num37++)
                            {
                                pModuleData[num37, k] = 0;
                            }
                        }
                        int num38 = pTotal - 1;
                        for (int l = 0; l <= num38; l++)
                        {
                            byte num39 = buffer4[l];
                            int num40 = 7;
                            do
                            {
                                int num41 = l * 8 + num40;
                                int num42 = QRCodeGetMaskBitGroup(lDeployOrderX[num41], lDeployOrderY[num41]);
                                pModuleData[lDeployOrderX[num41], lDeployOrderY[num41]] = (byte)(byte.MaxValue * (num39 & 1) ^ num42);
                                num39 = unchecked((byte)((uint)num39 >> 1));
                                num40 += -1;
                            }
                            while (num40 >= 0);
                        }
                        for (int m = numArray5[(int)lQRInquireVersion]; m >= 1; m += -1)
                        {
                            int num43 = m + pTotal * 8 - 1;
                            int num42 = QRCodeGetMaskBitGroup(lDeployOrderX[num43], lDeployOrderY[num43]);
                            pModuleData[lDeployOrderX[num43], lDeployOrderY[num43]] = (byte)(255 ^ num42);
                        }
                        byte num44 = QRCodeChooseMaskNumber(pModuleData, numArray5[(int)lQRInquireVersion] + pTotal * 8);
                        byte num45 = (byte)Math.Round(Math.Pow(2.0, num44));
                        byte num46 = (byte)(num44 + (int)QRSetECCRate * 8);
                        int startIndex = 0;
                        do
                        {
                            byte num47 = byte.Parse(strArray[num46].Substring(startIndex, 1));
                            pModuleData[lFormatFirstX[startIndex], lFormatFirstY[startIndex]] = (byte)(num47 * byte.MaxValue);
                            pModuleData[lFormatSecondX[startIndex], lFormatSecondY[startIndex]] = (byte)(num47 * byte.MaxValue);
                            startIndex++;
                        }
                        while (startIndex <= 14);
                        byte[,] buffer5 = new byte[num25 - 1 + 1 - 1 + 1, num25 - 1 + 1 - 1 + 1];
                        int num48 = 0;
                        int num49 = num25 - 1;
                        for (int num50 = 0; num50 <= num49; num50++)
                        {
                            int num51 = num25 - 1;
                            for (int num52 = 0; num52 <= num51; num52++)
                            {
                                bool flag18 = (pModuleData[num52, num50] & num45) > 0 | (buffer3[num48] & 1) == 1;
                                if (flag18)
                                {
                                    buffer5[num52, num50] = (byte)(1 | buffer3[num48] & 254);
                                }
                                else
                                {
                                    buffer5[num52, num50] = (byte)(0 | buffer3[num48] & 254);
                                }
                                num48++;
                            }
                            num48++;
                        }
                        QRGetData = buffer5;
                    }
                }
                return QRGetData;
            }
        }

        private static byte QRGetNumericCode(string pInput)
        {
            bool flag = pInput.ToDouble() >= 48.0 & pInput.ToDouble() < 58.0;
            byte QRGetNumericCode;
            if (flag)
            {
                QRGetNumericCode = (byte)Math.Round(pInput.ToDouble() - 48.0);
            }
            else
            {
                QRGetNumericCode = 0;
            }
            return QRGetNumericCode;
        }

        /// <summary>AddChechDigit</summary>
        public bool AddChechDigit { get; set; }

        /// <summary>QRInquireAlphaNumericBits</summary>
        public int QRInquireAlphaNumericBits
        {
            get
            {
                return lQRInquireAlphaNumericBits;
            }
        }

        /// <summary>QRInquireBinaryBits</summary>
        public int QRInquireBinaryBits
        {
            get
            {
                return lQRInquireBinaryBits;
            }
        }

        /// <summary>QRInquireModuleSize</summary>
        public int QRInquireModuleSize
        {
            get
            {
                return lQRInquireModuleSize;
            }
        }

        /// <summary>QRInquireNumericBits</summary>
        public int QRInquireNumericBits
        {
            get
            {
                return lQRInquireNumericBits;
            }
        }

        /// <summary>QRInquireTextType</summary>
        public QRTextTypes QRInquireTextType
        {
            get
            {
                return lQRInquireTextType;
            }
        }

        /// <summary>QRInquireVersion</summary>
        public QRVersions QRInquireVersion
        {
            get
            {
                return lQRInquireVersion;
            }
        }

        /// <summary>QRSetECCRate</summary>
        public QRECCRates QRSetECCRate { get; set; }

        /// <summary>QRSetTextType</summary>
        public QRTextTypes QRSetTextType { get; set; }

        /// <summary>QRSetVersion</summary>
        public QRVersions QRSetVersion
        {
            get
            {
                return lQRSetVersion;
            }
            set
            {
                bool flag = value >= QRVersions.Automatic & value <= QRVersions.Ver40;
                if (flag)
                {
                    lQRSetVersion = value;
                }
            }
        }

        /// <summary>WriteDebugInfo</summary>
        public bool WriteDebugInfo { get; set; }

        /// <summary>
        /// 生成指定二维码的Pos小票打印机的列图指令
        /// </summary>
        /// <param name="theText"></param>
        /// <param name="thePercentLow"></param>
        /// <param name="EncodingIsAscii"></param>
        /// <returns></returns>
        public static string GetPosImageCol(string theText, bool thePercentLow = false, bool EncodingIsAscii = false)
        {
            bool flag = theText.Length == 0;
            checked
            {
                string GetPosImageCol;
                if (flag)
                {
                    GetPosImageCol = "";
                }
                else
                {
                    QRCode dQRCode = new QRCode
                    {
                        QRSetVersion = QRVersions.Automatic,
                        QRSetTextType = QRTextTypes.Binary,
                        QRSetECCRate = thePercentLow ? QRECCRates.Low7Percent : QRECCRates.Medium15Percent
                    };
                    byte[,] dBytes = dQRCode.QRGetData(theText, EncodingIsAscii);
                    bool flag2 = dBytes.GetLength(0) * 8 > 384;
                    if (flag2)
                    {
                        GetPosImageCol = "\r\n(此处的二维码太大打印不下)\r\n";
                    }
                    else
                    {
                        StringBuilder dCode = new StringBuilder();
                        int dColCount = dBytes.GetLength(1);
                        int dLeft = (384 - dColCount * 8) / 8 / 2;
                        int num = dBytes.GetLength(0) - 1;
                        for (int xx = 0; xx <= num; xx += 3)
                        {
                            string dRowText = "\u001b*!" + ((char)((dColCount + dLeft) * 8 % 256)).ToString() + ((char)((dColCount + dLeft) * 8 / 256)).ToString();
                            dRowText += new string('\0', dLeft * 24);
                            int num2 = dColCount - 1;
                            for (int yy = 0; yy <= num2; yy++)
                            {
                                int dAsc = (dBytes[xx, yy] & 1) > 0 ? 255 : 0;
                                bool flag3 = xx + 1 >= dBytes.GetLength(0);
                                int dAsc2;
                                if (flag3)
                                {
                                    dAsc2 = 0;
                                }
                                else
                                {
                                    dAsc2 = (dBytes[xx + 1, yy] & 1) > 0 ? 255 : 0;
                                }
                                bool flag4 = xx + 2 >= dBytes.GetLength(0);
                                int dAsc3;
                                if (flag4)
                                {
                                    dAsc3 = 0;
                                }
                                else
                                {
                                    dAsc3 = (dBytes[xx + 2, yy] & 1) > 0 ? 255 : 0;
                                }
                                int nn = 0;
                                do
                                {
                                    dRowText = dRowText + ((char)dAsc).ToString() + ((char)dAsc2).ToString() + ((char)dAsc3).ToString();
                                    nn++;
                                }
                                while (nn <= 7);
                            }
                            dRowText += "\u001bJ\u0018";
                            dCode.Append(dRowText);
                        }
                        GetPosImageCol = dCode.ToString();
                    }
                }
                return GetPosImageCol;
            }
        }

        /// <summary>
        /// 使用行图模式生成打印指令
        /// </summary>
        /// <returns></returns>
        /// <remarks></remarks>
        public static string GetPosImageRow(string theText, bool thePercentLow = false, bool EncodingIsAscii = false)
        {
            QRCode dQRCode = new QRCode
            {
                QRSetVersion = QRVersions.Automatic,
                QRSetTextType = QRTextTypes.Binary,
                QRSetECCRate = thePercentLow ? QRECCRates.Low7Percent : QRECCRates.Medium15Percent
            };
            byte[,] dBytes = dQRCode.QRGetData(theText, EncodingIsAscii);
            {
                bool flag = dBytes.GetLength(0) * 8 > 384;
                string GetPosImageRow;
                if (flag)
                {
                    GetPosImageRow = "\r\n(此处的二维码太大打印不下)\r\n";
                }
                else
                {
                    StringBuilder dCode = new StringBuilder();
                    int dColCount = dBytes.GetLength(0);
                    int dLeft = (384 - dColCount * 8) / 8 / 2;
                    dCode.Append("\u001dv0\0");
                    dCode.Append(((char)((dColCount + dLeft) % 256)).ToString() + (char)((dColCount + dLeft) / 256)).ToString();
                    dCode.Append(((char)(dColCount * 8 % 256)).ToString() + (char)(dColCount * 8 / 256)).ToString();
                    int num = dColCount - 1;
                    for (int xx = 0; xx <= num; xx++)
                    {
                        string dByteLine = new string('\0', dLeft);
                        int num2 = dColCount - 1;
                        for (int yy = 0; yy <= num2; yy++)
                        {
                            dByteLine += ((dBytes[xx, yy] & 1) > 0 ? (char)255 : '\0').ToString();
                        }
                        int nn = 0;
                        do
                        {
                            dCode.Append(dByteLine);
                            nn++;
                        }
                        while (nn <= 7);
                    }
                    GetPosImageRow = dCode.ToString();
                }
                return GetPosImageRow;
            }
        }

        private int[,] gDataWords;
        private int[,] gECCWords;
        private int[,] gExtraDataWords;
        private int[,] gRSBlockCount;
        private byte[] lDeployOrderX;
        private byte[] lDeployOrderY;
        private byte[] lDeployTableX;
        private byte[] lDeployTableY;
        private readonly byte[] lFormatFirstX;
        private readonly byte[] lFormatFirstY;
        private byte[] lFormatSecondX;
        private byte[] lFormatSecondY;
        private int lQRInquireAlphaNumericBits;
        private int lQRInquireBinaryBits;
        private int lQRInquireModuleSize;
        private int lQRInquireNumericBits;
        private QRTextTypes lQRInquireTextType;
        private QRVersions lQRInquireVersion;
        private QRVersions lQRSetVersion;
        private byte[] lRSBlock;

        /// <summary>QRECCRates</summary>
        public enum QRECCRates
        {
            /// <summary>HighQuality30Percent</summary>
            HighQuality30Percent = 3,
            /// <summary>Low7Percent</summary>
            Low7Percent = 0,
            /// <summary>Medium15Percent</summary>
            Medium15Percent,
            /// <summary>Quality25Percent</summary>
            Quality25Percent
        }

        /// <summary>QRTextTypes</summary>
        [Flags]
        public enum QRTextTypes
        {
            /// <summary>AlphaNumeric</summary>
            AlphaNumeric = 2,
            /// <summary>Automatic</summary>
            Automatic = 0,
            /// <summary>Binary</summary>
            Binary = 4,
            /// <summary>Numeric</summary>
            Numeric = 1
        }

        /// <summary>QRVersions</summary>
        public enum QRVersions
        {
            /// <summary>Automatic</summary>
            Automatic,
            /// <summary>Ver01</summary>
            Ver01,
            /// <summary>Ver02</summary>
            Ver02,
            /// <summary>Ver03</summary>
            Ver03,
            /// <summary>Ver04</summary>
            Ver04,
            /// <summary>Ver05</summary>
            Ver05,
            /// <summary>Ver06</summary>
            Ver06,
            /// <summary>Ver07</summary>
            Ver07,
            /// <summary>Ver08</summary>
            Ver08,
            /// <summary>Ver09</summary>
            Ver09,
            /// <summary>Ver10</summary>
            Ver10,
            /// <summary>Ver11</summary>
            Ver11,
            /// <summary>Ver12</summary>
            Ver12,
            /// <summary>Ver13</summary>
            Ver13,
            /// <summary>Ver14</summary>
            Ver14,
            /// <summary>Ver15</summary>
            Ver15,
            /// <summary>Ver16</summary>
            Ver16,
            /// <summary>Ver17</summary>
            Ver17,
            /// <summary>Ver18</summary>
            Ver18,
            /// <summary>Ver19</summary>
            Ver19,
            /// <summary>Ver20</summary>
            Ver20,
            /// <summary>Ver21</summary>
            Ver21,
            /// <summary>Ver22</summary>
            Ver22,
            /// <summary>Ver23</summary>
            Ver23,
            /// <summary>Ver24</summary>
            Ver24,
            /// <summary>Ver25</summary>
            Ver25,
            /// <summary>Ver26</summary>
            Ver26,
            /// <summary>Ver27</summary>
            Ver27,
            /// <summary>Ver28</summary>
            Ver28,
            /// <summary>Ver29</summary>
            Ver29,
            /// <summary>Ver30</summary>
            Ver30,
            /// <summary>Ver31</summary>
            Ver31,
            /// <summary>Ver32</summary>
            Ver32,
            /// <summary>Ver33</summary>
            Ver33,
            /// <summary>Ver34</summary>
            Ver34,
            /// <summary>Ver35</summary>
            Ver35,
            /// <summary>Ver36</summary>
            Ver36,
            /// <summary>Ver37</summary>
            Ver37,
            /// <summary>Ver38</summary>
            Ver38,
            /// <summary>Ver39</summary>
            Ver39,
            /// <summary>Ver40</summary>
            Ver40
        }
    }
}
